home *** CD-ROM | disk | FTP | other *** search
- Path: library.erc.clarkson.edu!rpi!not-for-mail
- From: thorstad@dg-rtp.dg.com (Brian Thorstad)
- Newsgroups: comp.lang.c++.moderated,comp.lang.c++
- Subject: Re: Meaning of the specifier volatile?
- Date: 4 Jan 1996 00:26:02 -0000
- Organization: Data General Corporation, RTP, NC
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: herbs@connobj.com
- Message-ID: <4cf6qq$g0e@netlab.cs.rpi.edu>
- References: <4c9740$27n@netlab.cs.rpi.edu> <4cb5i3$5mr@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
-
- X-Original-Date: 03 Jan 1996 14:10:13 GMT
-
- In article <4cb5i3$5mr@netlab.cs.rpi.edu> Dave Nulton <dnult@axiom.net> writes:
-
- I'm no expert but here is what I know. The specifier volatile is
- a directive to the compiler that the variable declared volatile
- can change at any moment. The compiler will then make no
- assumptions about the contents of this variable, and will always
- re-check its value when used. An example of something that might
- use volatile variables is: a hardware interface to your PC which
- reads analog data and converts it to digital. Your program may
- read the data from the PC bus. However this data is always
- changing and your program should make know assumptions that the
- data is the same - it should always recheck the value.
-
- I believe volatile directs the compiler to not optimize the variable
- as the value can change w/o the compiler being aware. The compiler
- will not "always recheck the value", but will do exactly what you
- coded -- nothing more, nothing less. It is up to the programmer to
- appropriately access this value. A classic example is accessing such
- a value inside a loop, where normal optimization might pull that
- access outside the loop. Volatile can prevent this.
-
- >From the ARM: "volatile is a hint to the compiler to avoid aggressive
- optimization involving the object because the value of the object may
- be changed by means undetectable by a compiler."
-
- My $0.02.
- Brian
-
- I'm sure there are other less complicated applications which may
- benefit from volatile variables. I'm sure one of the many other
- experts on the net can elaborate.
-
- -dnult@axiom.net
- --
-
- +---------------------------+----------------------------------+
- | Brian Thorstad | Data General Corporation |
- | (thorstad@dg-rtp.dg.com) | |
- | Voice: (919) 248-6062 | 62 T.W. Alexander Dr. |
- | Fax: (919) 248-6108 | Research Triangle Park, NC 27709 |
- +---------------------------+----------------------------------+
-
- [ comp.lang.c++.moderated is a moderated newsgroup. Submit articles ]
- [ to <c++-submit@netlab.cs.rpi.edu>. The moderation policy can be ]
- [ retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>. ]
- [ Moderators can be reached at: c++-request@netlab.cs.rpi.edu. ]
-